<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>{{ username }}的聊天室</title>
</head>
<body>
    <h1>欢迎， {{ username }}</h1>
    
    <form method = "POST">
        <input type="hidden" id="username" name="username" value="{{username}}">
        <textarea cols="50" rows="4" name="message" id="message"></textarea>
        <br>
        <button>发送</button>
    </form>
    
    {% for message in chat_messages %}
        <p>({{ message.timestamp }}) {{ message.from }}: {{ message.message }}</p>
    {% endfor %}
    
    <script>
        let textbox = document.getElementById("message")
    
        let timer = setTimeout(function() {
            location.reload();
        }, 5000)
        
        textbox.onkeydown = function(e) {
            
            clearTimeout(timer)
            
            timer = setTimeout(function() {
                location.reload();
            }, 5000)
            
        }
        
    </script>
    
</body>
</html>